import mdf
import sys
from optparse import OptionParser
from itertools import *

#variables for command argument
index = None
usage = "mdf.py: [options]"
parser = OptionParser( usage=usage )
parser.add_option("-o","--output",  dest="output",                        default="./output",  type="string",help="output dir" )
parser.add_option("-p","--packages",dest="packages",                      default="./packages",type="string",help="package dir")
parser.add_option("-i",             dest="index",    action="store_true",default=False,                     help="index page")
parser.add_option("-a",             dest="articles", action="store_true",default=False,                     help="articles pages")
parser.add_option("-d",             dest="outdir",   action="store_true",default=False,                     help="create output dir")
parser.add_option("--all",          dest="all",      action="store_true",default=False,                     help="generate all site")

(cmd_options, args) = parser.parse_args()

pkgdir = cmd_options.packages
pkgrepo = mdf.PackageRepo( pkgdir, cmd_options.output )


if cmd_options.index:
	indexfile = mdf.IndexFile( cmd_options.output+"/index.html" )
	indexfile.render( pkgrepo.packages )
	aboutpage = mdf.AboutFile( cmd_options.output+"/about.html" )
	aboutpage.render()
	projectpage = mdf.Projects( cmd_options.output+"/projects.html" )
	projectpage.render()
	
	linkspage = mdf.Links( filename=cmd_options.output+"/links.html",
		datafile="data/links.json" )
	linkspage.render()
	
	librarypage = mdf.Library( filename=cmd_options.output+"/library.html",
		datafile="data/library.json" )
	librarypage.render()
	
	changepage = mdf.ChangeLog( filename=cmd_options.output+"/changelog.html",
		datafile="data/changelog.json" )
	changepage.render()

if cmd_options.outdir:
	out = mdf.OutputDir()
	out.copy_files()

if cmd_options.articles:
	print pkgrepo.list_pkgnames()
	pkgrepo.render_category_list( "writeup" )
	pkgrepo.render_articles( "writeup" )
	rsspage = mdf.RSS( cmd_options.output+"/posts/rss" )
	rsspage.add_packages( pkgrepo.packages )
	rsspage.render( pkgrepo.packages )
	rsspage = mdf.RSS( cmd_options.output+"/rss.xml" )
	rsspage.add_packages( pkgrepo.packages )
	rsspage.render( pkgrepo.packages )






